package com.housekeeping.housekeeping.administrator.adminsinformation.controller;

import com.housekeeping.housekeeping.administrator.adminsinformation.service.delete.DeleteService;
import com.housekeeping.housekeeping.administrator.adminsinformation.service.delete.DeleteServiceImpl;
import com.housekeeping.housekeeping.administrator.utils.ResponseEntity;
import com.housekeeping.housekeeping.administrator.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/information/delete")
public class DelController extends HttpServlet {
    private DeleteService deleteService=new DeleteServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求字符集
        req.setCharacterEncoding("utf-8");
        //设置响应字符集
        resp.setContentType("text/html;charset=utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        int count = deleteService.remove(id);
        ResponseEntity<Integer> entity=null;
        try {
            entity = ResponseEntity.success(count);
        }catch (Exception ex){
            entity=ResponseEntity.error(404,"系统错误");
        }
        ResponseUtils.responseJson(resp,entity);
    }
}
